home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 19.zip / BS1 part 19 / Util Collection 5 BS1.adf / Assembler / example.asm next >
Assembly Source File  |  1988-01-19  |  10KB  |  332 lines

  1. ;  EXAMPLE.ASM written 09/15/86 by Martin Murray
  2. ;        last modified 09/15/88 by Martin Murray
  3.  
  4. ;***************************************************************************
  5. ;*  THIS CODE IS IN NO WAY COPYRIGHT BY INOVATRONICS, INC.  IN FACT, YOU   *
  6. ;*  CAN DO ANYTHING WITH IT THAT YOU WANT TO DO.  JUST REMEMBER,           *
  7. ;*  INOVATRONICS, INC. WILL BEAR ABSOLUTELY NO RESPONSIBILITY FOR THE USE, *
  8. ;*  MISUSE, INABILITY TO USE OR INABLITY TO UNDERSTAND ANY OR ALL PARTS OF *
  9. ;*  THIS CODE.  ENJOY IT IN GOOD HEALTH.                                   *
  10. ;***************************************************************************
  11. ;***************************************************************************
  12. ;*  THE PURPOSE OF THE CODE IS TO LET YOU SEE WHAT YOUR PowerWindows2      *
  13. ;*  GENERATED SOURCE CODE WILL LOOK LIKE IN A PROGRAM.  IN MOST CASES, ALL *
  14. ;*  YOU SHOULD HAVE TO DO IS ASSEMBLE THIS FILE.  IT WILL  AUTOMATICALLY   *
  15. ;*  INCLUDE YOUR SOURCE FILE, PROVIDED IT IS IN THE DEFAULT DIRECTORY, AND *
  16. ;*  IS NAMED "example.i".  JUST ASSEMBLE IT, LINK IT AND RUN IT.  IT       *
  17. ;*  DEFAULTS TO TERMINATING WHEN THE CLOSE GADGET IS HIT, BUT IF YOU LOOK  *
  18. ;*  BELOW YOU'LL SEE HOW TO MAKE IT TERMINATE ON ANY EVENT AT ALL.         *
  19. ;*  PLEASE NOTE: IT IS DESIGNED FOR ONLY 1 WINDOW.  IT WILL LOAD A SCREEN  *
  20. ;*  AND A PALETTE IF THEY ARE PRESENT, BUT ONLY WINDOW NUMBER 1 AND ITS    *
  21. ;*  PROGENY.                                                               *
  22. ;***************************************************************************
  23.  
  24.     include    "exec/types.i"
  25.     include    "exec/io.i"
  26.     include    "exec/strings.i"
  27.     include    "libraries/dosextens.i"
  28.     include    "intuition/intuition.i"
  29.  
  30.     xref    _AbsExecBase
  31.  
  32. ;************   EQUATES
  33. NULL    equ    0
  34. InovaTools1_Required    equ    0    ;make this -1 if using InovaTools1
  35.  
  36. ;************   MACROS
  37. xlib    macro
  38.     xref    _LVO\1
  39.     endm
  40.  
  41. callsys   macro   (routine name to call, A6 must have base pointer of library)
  42.     xlib    \1
  43.     CALLLIB    _LVO\1
  44.     endm
  45.  
  46. call    macro    (address to call)
  47.     bsr    \1
  48.     endm
  49.  
  50. push    macro    (long ea to push)
  51.     move.l    \1,-(sp)
  52.     endm
  53.  
  54. pull    macro    (long ea to fetch without popping)
  55.     move.l    (sp),\1
  56.     endm
  57.  
  58. pop    macro    (long ea to pop into)
  59.     move.l    (sp)+,\1
  60.     endm
  61.  
  62.  
  63. ;*********   DATA AREA
  64.     DATA
  65.     include "example.i"        ;include the PowerWindows code
  66. Intuitionname:    string <'intuition.library'>
  67. InitialSP:    dc.l    0
  68. MeMyselfandI:    dc.l    0
  69. ReturnMsg:    dc.l    0
  70. _IntuitionBase:    dc.l    0
  71. CurrentWindow:    dc.l    0
  72.     ifd NewScreenStructure
  73. CurrentScreen:    dc.l    0
  74.     ifd Palette
  75. _GFXBase:    dc.l    0
  76. Graphicsname:    string <'graphics.library'>
  77.     endc
  78.     endc
  79.  
  80. ;************   PROGRAM START
  81.     CODE
  82. ;Intitialize by saving the stack pointer and finding our own task.
  83.     move.l    sp,InitialSP        ;save the stack pointer
  84.     move.l    _AbsExecBase,a6        ;get the system library address
  85.     sub.l    a1,a1
  86.     callsys    FindTask        ;please, I must find myself
  87.     move.l    d0,MeMyselfandI        ;save the address of the TCB list
  88.     move.l    d0,a0            ;  node in case we need it for some
  89.                     ;  reason
  90.     tst.l    pr_CLI(a0)        ;were we run by Workbench?
  91.     bne.s    1$            ;no-jump
  92.     lea    pw_MsgPort(a0),a0    ;wait for the startup message
  93.     push    a0
  94.     callsys    WaitPort
  95.     pop    a0            ;get it
  96.     callsys    GetMsg
  97.     move.l    d0,ReturnMsg        ;save the message
  98. 1$:
  99.     moveq    #0,d0            ;open intuition.library
  100.     lea    Intuitionname,a1
  101.     callsys    OpenLibrary
  102.     move.l    d0,_IntuitionBase    ;save her address
  103.     beq    FatalExit        ;quit NOW if no Intuition
  104. ;open Graphics Library if anything wants it
  105.     ifd _GFXBase
  106.     moveq    #0,d0            ;open the Graphics Library
  107.     lea    Graphicsname,a1
  108.     callsys    OpenLibrary
  109.     move.l    d0,_GFXBase        ;save the base pointer
  110.     beq    GraphicsError        ;leave if library not opened
  111.     endc
  112.  
  113. main:
  114.     move.l    _IntuitionBase,a6    ;A6 gets the pointer to Intuition
  115.  
  116. ;open the screen and load the palette, if appropriate
  117.     ifd NewScreenStructure
  118.     lea    NewScreenStructure,a0    ;try to open the screen
  119.     callsys    OpenScreen
  120.     move.l    d0,CurrentScreen    ;save the Screen structure address
  121.     beq    BigProblem        ;woops! if screen didn't open, leave
  122.                     ;  NOW
  123.     ifd Palette
  124.     move.l    d0,a0            ;give the Screen pointer to A0
  125.     lea    sc_ViewPort(a0),a0    ;point to the ViewPort structure
  126.                     ;  INSIDE the Screen structure
  127.     lea    Palette,a1        ;point to the Palette and get the
  128.     moveq    #PaletteColorCount,d0    ;  color count in D0
  129.     move.l    _GFXBase,a6        ;this next call goes through
  130.                     ;  Graphics
  131.     callsys    LoadRGB4
  132.     move.l    _IntuitionBase,a6    ;A6 gets the pointer to Intuition
  133.                     ;  again
  134.     endc
  135.     endc
  136.  
  137. ;do the opening of the window, et all.
  138.     lea    NewWindowStructure1,a0    ;point to the NewWindow structure
  139.     ifd NewScreenStructure
  140.     move.l    CurrentScreen,nw_Screen(a0)    ;save the screen pointer
  141.     endc
  142.     callsys    OpenWindow        ;open the window (gadgets will come
  143.     move.l    d0,CurrentWindow    ;  up too.)
  144.     beq    Exit            ;leave if couldn't open window
  145.  
  146. ;attach the menu if present
  147.     ifd MenuList1
  148.     move.l    d0,a0            ;window address to A0
  149.     lea    MenuList1,a1        ;menustrip pointed to by A1
  150.     callsys    SetMenuStrip
  151.     endc
  152.  
  153. ;draw the Knobs if any defined
  154.     ifd KnobList1
  155.     xref    _DrawKnobs
  156.     pea    KnobList1        ;pass the address of the first Knob
  157.     push    CurrentWindow        ;pass the Window address
  158.     jsr    _DrawKnobs        ;call InovaTools1
  159.     addq.l    #8,sp            ;(balance the stack)
  160.     endc
  161.  
  162. ;draw the IntuiText only if there is some
  163.     ifd IntuiTextList1
  164.     move.l    CurrentWindow,a0    ;get the RastPort address
  165.     move.l    wd_RPort(a0),a0
  166.     lea    IntuiTextList1,a1    ;print this list of IText structures
  167.     moveq    #0,d0            ;let the text position itself
  168.     move.l    d0,d1
  169.     callsys    PrintIText
  170.     endc
  171.  
  172. ;draw the Borders only if there are some of them
  173.     ifd BorderList1
  174.     move.l    CurrentWindow,a0    ;get the RastPort address
  175.     move.l    wd_RPort(a0),a0
  176.     lea    BorderList1,a1        ;draw this list of Border structures
  177.     moveq    #0,d0            ;let the borders position themselves
  178.     move.l    d0,d1
  179.     callsys    DrawBorder
  180.     endc
  181.  
  182. ;draw the Images only if there are some of them
  183.     ifd ImageList1
  184.     move.l    CurrentWindow,a0    ;get the RastPort address
  185.     move.l    wd_RPort(a0),a0
  186.     lea    ImageList1,a1        ;draw this list of Image structures
  187.     moveq    #0,d0            ;let the images position themselves
  188.     move.l    d0,d1
  189.     callsys    DrawImage
  190.     endc
  191.  
  192. ;do the Requester if Required
  193.     ifd RequesterStructure2
  194.     lea    RequesterStructure2,a0    ;point to the Requester structure
  195.     move.l    CurrentWindow,a1    ;put it in this window
  196.     callsys    Request
  197.     endc
  198.  
  199. ;now wait for the event we should terminate at.
  200. Execloop:
  201.     move.l    _AbsExecBase,a6        ;point to the system again
  202. loop:
  203.     move.l    CurrentWindow,a0    ;get the IDCMP port address and Wait
  204.     move.l    wd_UserPort(a0),a0    ;  on it
  205.     push    a0            ;save the port address
  206.     callsys    WaitPort
  207.     pop    a0            ;get the message
  208.     callsys    GetMsg
  209.     move.l    d0,a1            ;message address to A1
  210.     ifd HandleEvent
  211.     move.w    im_Code(a1),d2        ;grab the potential MENUNUM
  212.     move.l    im_IAddress(a1),d3    ;grab the potential Gadget address
  213.     endc
  214.     move.l    im_Class(a1),d4        ;save the event class in D4
  215.     callsys    ReplyMsg        ;reply the message
  216.  
  217.     ifd HandleEvent
  218.     cmp.l    #GADGETUP,d4        ;let the event handler do any
  219.     beq    DoGadgetEvent        ;  special code
  220.     cmp.l    #GADGETDOWN,d4
  221.     beq    DoGadgetEvent
  222.     ifd MenuList1
  223.     cmp.l    #MENUPICK,d4        ;if menu, let that code work
  224.     beq    DoMenuEvent
  225.     endc
  226.     endc
  227.  
  228.     ifd KnobList1
  229.     xref    _KnobGadgets
  230.     cmp.l    #MOUSEBUTTONS,d4    ;could the user be fiddling with the
  231.                     ;  Knobs?
  232.     bne.s    quit.test        ;no-jump
  233.     cmp.w    #SELECTDOWN,d2        ;make sure that it is the left mouse
  234.     bne    loop            ;  button being pressed DOWN
  235.     pea    KnobList1        ;pass the address of the first Knob
  236.     push    CurrentWindow        ;pass the window address
  237.     jsr    _KnobGadgets        ;let InovaTools1 process the Knobs
  238.     addq.l    #8,sp            ;(balance the stack)
  239.     bra    loop
  240.     endc
  241.  
  242. ;termination test -- change it to any other IDCMP event, just be sure that
  243. ;  your IDCMP flags are set properly
  244.     cmp.l    #CLOSEWINDOW,d4        ;should we terminate now?
  245.     bne    loop            ;loop if not
  246.  
  247. quit:
  248.     move.l    _IntuitionBase,a6    ;be sure to do next through
  249.                     ;  Intuition
  250.  
  251. ;detach the menu if present
  252.     ifd MenuList1
  253.     move.l    CurrentWindow,a0    ;window address to A0
  254.     callsys    ClearMenuStrip
  255.     endc
  256.  
  257.     move.l    CurrentWindow,a0    ;close the window
  258.     callsys    CloseWindow
  259.  
  260. ;************   PROGRAM EXIT
  261. Exit:
  262.     ifd NewScreenStructure
  263.     move.l    CurrentScreen,a0    ;close the screen
  264.     callsys    CloseScreen
  265.     endc
  266. BigProblem:
  267.     move.l    _AbsExecBase,a6
  268.     ifd _GFXBase
  269.     move.l    _GFXBase,a1        ;close Graphics if it is real
  270.     callsys    CloseLibrary
  271.     endc
  272. GraphicsError:
  273.     move.l    _IntuitionBase,a1    ;close Intuition
  274.     callsys    CloseLibrary
  275. FatalExit:
  276.     move.l    ReturnMsg,d0        ;reply to any WorkBench message
  277.     beq.s    1$            ;jump if none
  278.     move.l    a1,d0            ;point with this here register
  279.     callsys    ReplyMsg        ;Reply the message
  280. 1$:
  281.     moveq    #0,d0            ;no error code returned
  282.     move.l    InitialSP,sp        ;return to the caller
  283.     rts
  284.  
  285.  
  286. ;****************************     SUBROUTINES   *****************************
  287.     ifd HandleEvent
  288.  
  289. DoGadgetEvent:
  290.     move.l    _IntuitionBase,a6    ;be sure to do next through
  291.                     ;  Intuition
  292.     move.l    d3,d0            ;send the gadget address in D0
  293.     jsr    HandleEvent        ;it comes back in D0, so just go!
  294.     bra    Execloop        ;go back to get ExecBase again
  295.  
  296.     ifd MenuList1
  297. DoMenuEvent:
  298.     move.l    _IntuitionBase,a6    ;be sure to do next through
  299.                     ;  Intuition
  300.     moveq    #0,d0            ;ask Intuition for the MenuItem
  301.                     ;  address
  302.     move.w    d2,d0            ;send the MENUNUM
  303.     lea    MenuList1,a0        ;send the menu address
  304.     callsys    ItemAddress
  305.     jsr    HandleEvent        ;it comes back in D0, so just go!
  306.     bra    Execloop        ;go back to get ExecBase again
  307.     endc
  308.  
  309.     ifd InovaTools1_Required
  310.     xref    _DragGadget
  311.     xref    _PopUpMenu
  312. HandleDragGadget:
  313.     move.l    d0,a0            ;move the gadget pointer to A0
  314.     push    gg_SpecialInfo(a0)    ;pass the pointer to the DragInfo
  315.     push    CurrentWindow        ;  structure and to the window that
  316.     jsr    _DragGadget        ;  the DragGadget is in
  317.     addq.l    #8,sp            ;(balance the stack)
  318.     bra    Execloop        ;go back to get ExecBase again
  319.     
  320. HandlePopUpGadget:
  321.     move.l    d0,a0            ;move the gadget pointer to A0
  322.     push    gg_SpecialInfo(a0)    ;pass the pointer to the PopUp menu
  323.     push    CurrentWindow        ;  structure and to the window that
  324.     jsr    _PopUpMenu        ;  the PopUpGadget is in
  325.     addq.l    #8,sp            ;(balance the stack)
  326.     bra    Execloop        ;go back to get ExecBase again
  327.     endc
  328.  
  329.     endc
  330.  
  331.     end
  332.